/**
 * 
 */
package com.effectivsocial.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.envers.Audited;
import org.joda.time.DateTime;


/**
 * @author Dhrubo
 * @param <T>
 * @param <ID>
 * 
 */
@Audited
@MappedSuperclass
@EqualsAndHashCode(exclude={"createdBy", "lastModifiedBy", "createdDate", "lastModifiedDate", "deleted", "version"})
@ToString(exclude={"createdBy", "lastModifiedBy", "createdDate", "lastModifiedDate", "deleted", "version"})
public abstract class PersistentObject<U, ID  extends Serializable> implements Serializable{

	private static final long serialVersionUID = 1L;
	
	@Getter @Setter
	@Id
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(name = "uuid", strategy = "uuid2")
	@Column(name = "id", updatable = false, nullable = false, unique = true)
	private ID id;
	
		
	@Getter @Setter
	@OneToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "created_by", referencedColumnName = "user_id", nullable = false, updatable = false)
	private U createdBy;
	
	@Getter @Setter
	@OneToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "last_modified_by", referencedColumnName = "user_id", nullable = false, updatable = true)
	private U lastModifiedBy;
	
	@Getter @Setter
	@Temporal(TemporalType.TIMESTAMP)
	@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
	@Column(name = "created_date", nullable = false, updatable = false)
	private DateTime createdDate;
	
	@Getter @Setter
	@Temporal(TemporalType.TIMESTAMP)
	@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
	@Column(name = "last_modified_date", nullable = false, updatable = true)
	private DateTime lastModifiedDate;
	
	@Getter @Setter
	@Column(name = "deleted")
	private boolean deleted;
	
	@Getter @Setter
	@Version
	@Column(name = "version")
	private int version;
	
}
